﻿using xl.webapi.sqlsugar_helper;

namespace ImClientApi.Utils
{

    /// <summary>
    /// Db操作实例
    /// </summary>
    public class DbUtils
    {
        /// <summary>
        /// 私有构造函数，防止外部实例化
        /// </summary>
        private DbUtils()
        {
        }

        private static SqlSugarHelper? _dbHelper = null;
        private static object _lockObj = new object();

        /// <summary>
        /// 公共的静态属性，提供全局访问点
        /// </summary>
        public static SqlSugarHelper DbHelper
        {
            get
            {
                lock (_lockObj)
                {
                    // 如果实例不存在，则创建一个新实例
                    if (_dbHelper == null)
                    {
                        lock (_lockObj)
                        {
                            _dbHelper = new SqlSugarHelper(ConfigUtils.GetConfigToString("DbConn"), ConfigUtils.GetConfigToString("DbType"));
                        }
                    }
                    return _dbHelper;
                }
            }
        }
    }
}
